<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要Git子模块相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV01-Git-06-子模块">
<meta property="og:url" content="https://sumumm.github.io/post/16811b15.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要Git子模块相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2025-06-02T06:43:43.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.070Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://sumumm.github.io/post/16811b15.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":"","permalink":"https://sumumm.github.io/post/16811b15.html","path":"post/16811b15.html","title":"LV01-Git-06-子模块"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV01-Git-06-子模块 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%AD%90%E6%A8%A1%E5%9D%97"><span class="nav-text">一、子模块</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%87%BA%E7%8E%B0%E7%9A%84%E9%97%AE%E9%A2%98"><span class="nav-text">1. 出现的问题 </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-Git%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95"><span class="nav-text">2. Git的解决办法</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E5%9F%BA%E6%9C%AC%E7%94%A8%E6%B3%95"><span class="nav-text">二、基本用法</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84"><span class="nav-text">1. 项目结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%88%9B%E5%BB%BA%E7%89%88%E6%9C%AC%E5%BA%93"><span class="nav-text">2. 创建版本库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-project"><span class="nav-text">2.1 project</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-module-a"><span class="nav-text">2.2 module_a</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="nav-text">2.3 目录结构</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%BC%95%E5%85%A5%E5%AD%90%E6%A8%A1%E5%9D%97"><span class="nav-text">3. 引入子模块</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E6%80%8E%E5%BC%95%E5%85%A5%E5%AD%90%E6%A8%A1%E5%9D%97%EF%BC%9F"><span class="nav-text">3.1 怎引入子模块？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E6%9C%89%E4%BB%80%E4%B9%88%E5%8F%98%E5%8C%96%EF%BC%9F"><span class="nav-text">3.2 有什么变化？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E6%8F%90%E4%BA%A4%E5%AD%90%E6%A8%A1%E5%9D%97%E7%9A%84%E5%BC%95%E5%85%A5"><span class="nav-text">3.3 提交子模块的引入</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E4%BF%AE%E6%94%B9%E5%AD%90%E6%A8%A1%E5%9D%97"><span class="nav-text">4. 修改子模块</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E5%9C%A8%E5%AD%90%E6%A8%A1%E5%9D%97%E4%BF%AE%E6%94%B9%E4%BC%9A%E5%BD%B1%E5%93%8D%E7%88%B6%E9%A1%B9%E7%9B%AE%E5%90%97"><span class="nav-text">4.1 在子模块修改会影响父项目吗</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-1-%E5%AE%9E%E8%B7%B5%E4%B8%80%E4%B8%8B"><span class="nav-text">4.1.1 实践一下</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-1-2-%E7%BB%93%E8%AE%BA"><span class="nav-text">4.1.2 结论</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E5%9C%A8%E7%88%B6%E9%A1%B9%E7%9B%AE%E4%BF%AE%E6%94%B9%E5%AD%90%E6%A8%A1%E5%9D%97%EF%BC%9F"><span class="nav-text">4.2 在父项目修改子模块？</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-1-%E5%AE%9E%E8%B7%B5%E4%B8%80%E4%B8%8B"><span class="nav-text">4.2.1 实践一下</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-2-%E7%BB%93%E8%AE%BA"><span class="nav-text">4.2.2 结论</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E6%9B%B4%E6%96%B0%E5%AD%90%E6%A8%A1%E5%9D%97"><span class="nav-text">5. 更新子模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E5%88%A0%E9%99%A4%E5%AD%90%E6%A8%A1%E5%9D%97"><span class="nav-text">6. 删除子模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E6%9F%A5%E7%9C%8B%E5%AD%90%E6%A8%A1%E5%9D%97"><span class="nav-text">7. 查看子模块</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93"><span class="nav-text">三、远程仓库</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%B7%BB%E5%8A%A0%E5%AD%90%E6%A8%A1%E5%9D%97"><span class="nav-text">1. 添加子模块</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%9B%B4%E6%96%B0%E5%AD%90%E6%A8%A1%E5%9D%97"><span class="nav-text">2. 更新子模块</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E6%80%8E%E4%B9%88%E6%9B%B4%E6%96%B0%E8%BF%9C%E7%A8%8B%E6%9C%80%E6%96%B0%E7%89%88%E6%9C%AC%EF%BC%9F"><span class="nav-text">2.1 怎么更新远程最新版本？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E4%B8%8D%E5%8A%A0%E2%80%93remote%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%8D%E8%A1%8C%EF%BC%9F"><span class="nav-text">2.2 不加–remote为什么不行？</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-1-%E6%97%A0-remote-%E5%8F%82%E6%95%B0"><span class="nav-text">2.2.1 无 --remote 参数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-%E4%BD%BF%E7%94%A8-remote-%E5%8F%82%E6%95%B0"><span class="nav-text">2.2.2 使用 --remote 参数</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E6%80%8E%E4%B9%88%E7%A1%AE%E5%AE%9A%E5%AD%90%E6%A8%A1%E5%9D%97%E7%89%88%E6%9C%AC%EF%BC%9F"><span class="nav-text">2.3 怎么确定子模块版本？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E5%90%8C%E6%AD%A5%E9%85%8D%E7%BD%AE%E5%8F%98%E6%9B%B4"><span class="nav-text">2.4 同步配置变更</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-1-%E6%8F%90%E4%BA%A4%E5%AD%90%E6%A8%A1%E5%9D%97%E7%9A%84%E6%94%B9%E5%8A%A8"><span class="nav-text">2.4.1 提交子模块的改动</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-2-%E6%96%B0-URL-%E9%85%8D%E7%BD%AE"><span class="nav-text">2.4.2 新 URL 配置</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-clone%E5%B8%A6%E5%AD%90%E6%A8%A1%E5%9D%97%E7%9A%84%E4%BB%93%E5%BA%93"><span class="nav-text">3. clone带子模块的仓库</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/16811b15.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV01-Git-06-子模块 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV01-Git-06-子模块
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2025-06-02 14:43:43" itemprop="dateCreated datePublished" datetime="2025-06-02T14:43:43+08:00">2025-06-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/" itemprop="url" rel="index"><span itemprop="name">开发工具</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/" itemprop="url" rel="index"><span itemprop="name">03版本控制</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4.9k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>18 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要Git子模块相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-06-%E5%AD%90%E6%A8%A1%E5%9D%97/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">Git 官网</td><td align="left"><a href="https://git-scm.com/" target="_blank">https://git-scm.com/ <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Git 官方文档</td><td align="left"><a href="https://git-scm.com/doc" target="_blank">https://git-scm.com/doc <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Pro Git Book</td><td align="left"><a href="https://git-scm.com/book/zh/v2" target="_blank">https://git-scm.com/book/zh/v2 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Git 快速使用指南</td><td align="left"><a href="https://training.github.com/downloads/zh_CN/github-git-cheat-sheet/" target="_blank">https://training.github.com/downloads/zh_CN/github-git-cheat-sheet/ <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Visual Git Cheat Sheet</td><td align="left"><a href="https://ndpsoftware.com/git-cheatsheet.html#loc=index" target="_blank">https://ndpsoftware.com/git-cheatsheet.html#loc=index <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<h1 id="一、子模块"><a href="#一、子模块" class="headerlink" title="一、子模块"></a><font size=3>一、子模块</font></h1><h2 id="1-出现的问题"><a href="#1-出现的问题" class="headerlink" title="1. 出现的问题 "></a><font size=3>1. 出现的问题 </font></h2><p>有种情况我们经常会遇到：某个工作中的项目需要包含并使用另一个项目。 也许是第三方库，或者独立开发的，用于多个父项目的库。 现在问题来了：想要把它们当做两个独立的项目，同时又想在一个项目中使用另一个。</p>
<p>就比如，我的笔记博客网站，它是基于hexo的，它不仅包含hexo的架构文件，还包含主题，还包含我的笔记：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">.</span><br><span class="line">├── ...</span><br><span class="line">├── source</span><br><span class="line">│   ├── 404.md</span><br><span class="line">│   ├── about</span><br><span class="line">│   ├── categories</span><br><span class="line">│   ├── _data</span><br><span class="line">│   ├── docs</span><br><span class="line">│   ├── images</span><br><span class="line">│   └── _posts      # 笔记所在目录</span><br><span class="line">│       ├── hello-world.md</span><br><span class="line">│       └── hexo-theme-next</span><br><span class="line">└── themes          # 主题所在目录</span><br><span class="line">    └── next</span><br></pre></td></tr></table></figure>

<p>那么这个仓库的提交记录中就会包含笔记的更新和站点的更新，但是这两者是没什么关系的，当提交记录多起来之后，我想要找站点提交记录，但是笔记更新了好几百次，这找起来就很麻烦。那么，我是不是可以换一个单独的仓库来作为笔记的仓库，在生成静态网页的时候把笔记拷贝过来？当然可以了，只需要保证hexo生成静态网页的时候，笔记存在于对应的位置即可。</p>
<h2 id="2-Git的解决办法"><a href="#2-Git的解决办法" class="headerlink" title="2. Git的解决办法"></a><font size=3>2. Git的解决办法</font></h2><p>Git 通过子模块来解决这个问题。 子模块允许我们将一个 Git 仓库作为另一个 Git 仓库的子目录。 它能让我们将另一个仓库克隆到自己的项目中，同时还保持提交的独立。</p>
<h1 id="二、基本用法"><a href="#二、基本用法" class="headerlink" title="二、基本用法"></a><font size=3>二、基本用法</font></h1><h2 id="1-项目结构"><a href="#1-项目结构" class="headerlink" title="1. 项目结构"></a><font size=3>1. 项目结构</font></h2><p>我们现在要创建这样一个结构的项目：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">projext/</span><br><span class="line">├── module_a</span><br><span class="line">└── readme.md</span><br></pre></td></tr></table></figure>

<p>其中 module_a 需要是一个单独的版本库。我们接下来就来了解一下子模块怎么使用。</p>
<h2 id="2-创建版本库"><a href="#2-创建版本库" class="headerlink" title="2. 创建版本库"></a><font size=3>2. 创建版本库</font></h2><h3 id="2-1-project"><a href="#2-1-project" class="headerlink" title="2.1 project"></a><font size=3>2.1 project</font></h3><p>我们创建project版本库，并提交readme.md文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">git init project</span><br><span class="line">cd project</span><br><span class="line">echo &quot;This is project!&quot; &gt; readme.md</span><br><span class="line"></span><br><span class="line">git add .</span><br><span class="line">git commit -m &quot;add readme.md&quot;</span><br></pre></td></tr></table></figure>

<h3 id="2-2-module-a"><a href="#2-2-module-a" class="headerlink" title="2.2 module_a"></a><font size=3>2.2 module_a</font></h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">git init module_a</span><br><span class="line">cd module_a</span><br><span class="line">echo &quot;This is module_a!&quot; &gt; readme.md</span><br><span class="line"></span><br><span class="line">git add .</span><br><span class="line">git commit -m &quot;add module_a readme.md&quot;</span><br></pre></td></tr></table></figure>

<h3 id="2-3-目录结构"><a href="#2-3-目录结构" class="headerlink" title="2.3 目录结构"></a><font size=3>2.3 目录结构</font></h3><p>现在目录结构如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule$ tree</span><br><span class="line">.</span><br><span class="line">├── module_a</span><br><span class="line">│   └── readme.md</span><br><span class="line">└── project</span><br><span class="line">    └── readme.md</span><br><span class="line"></span><br><span class="line">2 directories, 2 files</span><br></pre></td></tr></table></figure>

<p>现在两个仓库互不干扰。</p>
<h2 id="3-引入子模块"><a href="#3-引入子模块" class="headerlink" title="3. 引入子模块"></a><font size=3>3. 引入子模块</font></h2><h3 id="3-1-怎引入子模块？"><a href="#3-1-怎引入子模块？" class="headerlink" title="3.1 怎引入子模块？"></a><font size=3>3.1 怎引入子模块？</font></h3><p>我们现在在project中引入子模块module_a：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd project</span><br><span class="line">git submodule add ../module_a submodule_a</span><br></pre></td></tr></table></figure>

<p>然后就报错了：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git submodule add ../module_a submodule_a</span><br><span class="line">正克隆到 &#x27;/home/sumu/submodule/project/submodule_a&#x27;...</span><br><span class="line">fatal: 传输 &#x27;file&#x27; 不允许</span><br><span class="line">fatal: 无法克隆 &#x27;/home/sumu/submodule/module_a&#x27; 到子模组路径 &#x27;/home/sumu/submodule/project/submodule_a&#x27;</span><br></pre></td></tr></table></figure>

<p>这是因为 Git 默认不允许使用本地文件传输。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global protocol.file.allow always</span><br></pre></td></tr></table></figure>

<p>然后重新添加就可以了，添加后我们可以看一下状态：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git submodule add ../module_a submodule_a</span><br><span class="line">正克隆到 &#x27;/home/sumu/submodule/project/submodule_a&#x27;...</span><br><span class="line">完成。</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git status </span><br><span class="line">位于分支 master</span><br><span class="line">要提交的变更：</span><br><span class="line">  （使用 &quot;git restore --staged &lt;文件&gt;...&quot; 以取消暂存）</span><br><span class="line">        新文件：   .gitmodules</span><br><span class="line">        新文件：   submodule_a</span><br></pre></td></tr></table></figure>

<h3 id="3-2-有什么变化？"><a href="#3-2-有什么变化？" class="headerlink" title="3.2 有什么变化？"></a><font size=3>3.2 有什么变化？</font></h3><p>首先应当注意到新的 <code>.gitmodules</code> 文件。 该配置文件保存了项目 URL 与已经拉取的本地目录之间的映射：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[submodule &quot;submodule_a&quot;]</span><br><span class="line">	path = submodule_a</span><br><span class="line">	url = ../module_a</span><br></pre></td></tr></table></figure>

<p>如果有多个子模块，该文件中就会有多条记录。 要重点注意的是，该文件也像 <code>.gitignore</code> 文件一样受到（通过）版本控制。 它会和该项目的其他部分一同被拉取推送。 这就是克隆该项目的人知道去哪获得子模块的原因。</p>
<p>在 <code>git status</code> 输出中列出的另一个是项目文件夹记录。 如果你运行 <code>git diff</code>，会看到类似下面的信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git diff --cached submodule_a/</span><br><span class="line">diff --git a/submodule_a b/submodule_a</span><br><span class="line">new file mode 160000</span><br><span class="line">index 0000000..6df6c91</span><br><span class="line">--- /dev/null</span><br><span class="line">+++ b/submodule_a</span><br><span class="line">@@ -0,0 +1 @@</span><br><span class="line">+Subproject commit 6df6c91c360cc2091d4b48b1b52f6f4c95dd7c1a</span><br></pre></td></tr></table></figure>

<p>虽然 <code>submodule_a</code> 是工作目录中的一个子目录，但 Git 还是会将它视作一个子模块。当不在那个目录中时，Git 并不会跟踪它的内容， 而是将它看作子模块仓库中的某个具体的提交。</p>
<p>如果想看到更漂亮的差异输出，可以给 <code>git diff</code> 传递 <code>--submodule</code> 选项:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git diff --cached --submodule</span><br></pre></td></tr></table></figure>

<p>会有如下输出：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git diff --cached --submodule</span><br><span class="line">diff --git a/.gitmodules b/.gitmodules</span><br><span class="line">new file mode 100644</span><br><span class="line">index 0000000..268bbe2</span><br><span class="line">--- /dev/null</span><br><span class="line">+++ b/.gitmodules</span><br><span class="line">@@ -0,0 +1,3 @@</span><br><span class="line">+[submodule &quot;submodule_a&quot;]</span><br><span class="line">+       path = submodule_a</span><br><span class="line">+       url = ../module_a</span><br><span class="line">Submodule submodule_a 0000000...6df6c91 (new submodule)</span><br></pre></td></tr></table></figure>

<h3 id="3-3-提交子模块的引入"><a href="#3-3-提交子模块的引入" class="headerlink" title="3.3 提交子模块的引入"></a><font size=3>3.3 提交子模块的引入</font></h3><p>当提交时，会看到类似下面的信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git add .</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git commit  -m &quot;引入子模块&quot;</span><br><span class="line">[master 0ab9af8] 引入子模块</span><br><span class="line"> 2 files changed, 4 insertions(+)</span><br><span class="line"> create mode 100644 .gitmodules</span><br><span class="line"> create mode 160000 submodule_a</span><br></pre></td></tr></table></figure>

<h2 id="4-修改子模块"><a href="#4-修改子模块" class="headerlink" title="4. 修改子模块"></a><font size=3>4. 修改子模块</font></h2><h3 id="4-1-在子模块修改会影响父项目吗"><a href="#4-1-在子模块修改会影响父项目吗" class="headerlink" title="4.1 在子模块修改会影响父项目吗"></a><font size=3>4.1 在子模块修改会影响父项目吗</font></h3><h4 id="4-1-1-实践一下"><a href="#4-1-1-实践一下" class="headerlink" title="4.1.1 实践一下"></a><font size=3>4.1.1 实践一下</font></h4><p>修改子模块之后只对子模块的版本库产生影响，对父项目的版本库不会产生任何影响，我们修改子模块的内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd module_a</span><br><span class="line">echo &quot;modify module_a 1!&quot; &gt;&gt; readme.md</span><br></pre></td></tr></table></figure>

<p>我们可以去父项目查看一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/module_a$ git status </span><br><span class="line">位于分支 master</span><br><span class="line">尚未暂存以备提交的变更：</span><br><span class="line">  （使用 &quot;git add &lt;文件&gt;...&quot; 更新要提交的内容）</span><br><span class="line">  （使用 &quot;git restore &lt;文件&gt;...&quot; 丢弃工作区的改动）</span><br><span class="line">        修改：     readme.md</span><br><span class="line"></span><br><span class="line">修改尚未加入提交（使用 &quot;git add&quot; 和/或 &quot;git commit -a&quot;）</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/module_a$ cd ../project/</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git status </span><br><span class="line">位于分支 master</span><br><span class="line">无文件要提交，干净的工作区</span><br></pre></td></tr></table></figure>

<p>可以发现是父项目是没有做任何修改的。我们先撤销修改：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -- .</span><br></pre></td></tr></table></figure>

<h4 id="4-1-2-结论"><a href="#4-1-2-结论" class="headerlink" title="4.1.2 结论"></a><font size=3>4.1.2 结论</font></h4><p>子模块是独立的，怎么修改都不会影响父项目。</p>
<h3 id="4-2-在父项目修改子模块？"><a href="#4-2-在父项目修改子模块？" class="headerlink" title="4.2 在父项目修改子模块？"></a><font size=3>4.2 在父项目修改子模块？</font></h3><h4 id="4-2-1-实践一下"><a href="#4-2-1-实践一下" class="headerlink" title="4.2.1 实践一下"></a><font size=3>4.2.1 实践一下</font></h4><p>例如，我们在project中修改子模块的文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd project</span><br><span class="line">echo &quot;modify module_a (project/submodule_a)!&quot; &gt;&gt; submodule_a/readme.md</span><br></pre></td></tr></table></figure>

<p>然后我们看一下状态:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ echo &quot;modify module_a (project/submodule_a)!&quot; &gt;&gt; submodule_a/readme.md</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git status </span><br><span class="line">位于分支 master</span><br><span class="line">尚未暂存以备提交的变更：</span><br><span class="line">  （使用 &quot;git add &lt;文件&gt;...&quot; 更新要提交的内容）</span><br><span class="line">  （使用 &quot;git restore &lt;文件&gt;...&quot; 丢弃工作区的改动）</span><br><span class="line">  （提交或丢弃子模组中未跟踪或修改的内容）</span><br><span class="line">        修改：     submodule_a (修改的内容)</span><br><span class="line"></span><br><span class="line">修改尚未加入提交（使用 &quot;git add&quot; 和/或 &quot;git commit -a&quot;）</span><br></pre></td></tr></table></figure>

<p>我们尝试提交一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git add .</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git commit  -m &quot;父项目修改子模块&quot;</span><br><span class="line">位于分支 master</span><br><span class="line">尚未暂存以备提交的变更：</span><br><span class="line">  （使用 &quot;git add &lt;文件&gt;...&quot; 更新要提交的内容）</span><br><span class="line">  （使用 &quot;git restore &lt;文件&gt;...&quot; 丢弃工作区的改动）</span><br><span class="line">  （提交或丢弃子模组中未跟踪或修改的内容）</span><br><span class="line">        修改：     submodule_a (修改的内容)</span><br><span class="line"></span><br><span class="line">修改尚未加入提交（使用 &quot;git add&quot; 和/或 &quot;git commit -a&quot;）</span><br></pre></td></tr></table></figure>

<p>会发现根本没有办法修改。那我们进入<code>project/submodule_a</code>再试一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project/submodule_a$ git status </span><br><span class="line">头指针分离于 6df6c91</span><br><span class="line">尚未暂存以备提交的变更：</span><br><span class="line">  （使用 &quot;git add &lt;文件&gt;...&quot; 更新要提交的内容）</span><br><span class="line">  （使用 &quot;git restore &lt;文件&gt;...&quot; 丢弃工作区的改动）</span><br><span class="line">        修改：     readme.md</span><br><span class="line"></span><br><span class="line">修改尚未加入提交（使用 &quot;git add&quot; 和/或 &quot;git commit -a&quot;）</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project/submodule_a$ git add .</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project/submodule_a$ git commit -m &quot;父项目修改子模块&quot;</span><br><span class="line">[分离头指针 0765ed8] 父项目修改子模块</span><br><span class="line"> 1 file changed, 1 insertion(+)</span><br></pre></td></tr></table></figure>

<p>发现这个时候是可以的。那么这个时候我们查看一下两个目录的提交记录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project/submodule_a$ git mylog </span><br><span class="line">* [sumu] 0765ed8 : 父项目修改子模块  (HEAD) (2025-06-02 13:24:44) </span><br><span class="line">* [sumu] 6df6c91 : add module_a readme.md  (origin/master, origin/HEAD, master) (2025-06-02 12:56:42) </span><br><span class="line"></span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project/submodule_a$ cd ..</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git mylog </span><br><span class="line">* [sumu] 0ab9af8 : 引入子模块  (HEAD -&gt; master) (2025-06-02 13:09:43) </span><br><span class="line">* [sumu] f4ac034 : add readme.md  (2025-06-02 12:54:04) </span><br></pre></td></tr></table></figure>

<p>会发现，我们在 <code>project/submodule_a</code>中的提交记录只能在子模块目录下看到，我们回到父项目目录，提交记录就没有发生变化。</p>
<h4 id="4-2-2-结论"><a href="#4-2-2-结论" class="headerlink" title="4.2.2 结论"></a><font size=3>4.2.2 结论</font></h4><p>（1）在父项目中，可以修改子模块，但是无法在父项目中对子模块的修改进行提交和记录。</p>
<p>（2）从父项目进入子模块的目录可以正常提交子模块的修改，但是提交记录只会出现在父项目下的子模块目录，而不会出现在父项目的提交中。</p>
<h2 id="5-更新子模块"><a href="#5-更新子模块" class="headerlink" title="5. 更新子模块"></a><font size=3>5. 更新子模块</font></h2><p>通过上面的了解，我们知道子模块修改后是独立的，那么父项目怎么获取最新的子模块？可以在父项目目录下执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git submodule update</span><br></pre></td></tr></table></figure>

<p>我们上面在父项目中对子模块修改了，但是子模块自己的目录并没有做任何改变，我们来更新一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git submodule update</span><br><span class="line">子模组路径 &#x27;submodule_a&#x27;：检出 &#x27;6df6c91c360cc2091d4b48b1b52f6f4c95dd7c1a&#x27;</span><br><span class="line"></span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ git mylog </span><br><span class="line">* [sumu] 0ab9af8 : 引入子模块  (HEAD -&gt; master) (2025-06-02 13:09:43) </span><br><span class="line">* [sumu] f4ac034 : add readme.md  (2025-06-02 12:54:04) </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project$ cd submodule_a/</span><br><span class="line">sumu@sumu-virtual-machine:~/submodule/project/submodule_a$ git mylog </span><br><span class="line">* [sumu] 6df6c91 : add module_a readme.md  (HEAD, origin/master, origin/HEAD, master) (2025-06-02 12:56:42)</span><br></pre></td></tr></table></figure>

<p>从这里就可以看出，这个命令强制更新子模块的源目录的内容并且覆盖了父项目中的子模块。</p>
<h2 id="6-删除子模块"><a href="#6-删除子模块" class="headerlink" title="6. 删除子模块"></a><font size=3>6. 删除子模块</font></h2><p>删除子模块比较麻烦，需要手动删除相关的文件，否则在添加子模块时有可能出现错误。</p>
<ul>
<li>（1）删除子模块目录</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd project</span><br><span class="line">git rm --cached submodule_a</span><br><span class="line">rm -rf submodule_a</span><br></pre></td></tr></table></figure>

<ul>
<li>（2）删除 <code>.gitmodules</code> 文件中相关子模块的信息，类似以下信息：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[submodule &quot;submodule_a&quot;]</span><br><span class="line">	path = submodule_a</span><br><span class="line">	url = ../module_a</span><br></pre></td></tr></table></figure>

<ul>
<li>（3）删除 <code>.git/config</code> 中相关子模块信息，类似于：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[submodule &quot;submodule_a&quot;]</span><br><span class="line">        url = /home/sumu/submodule/module_a</span><br><span class="line">        active = true</span><br></pre></td></tr></table></figure>

<ul>
<li>（4）删除 <code>.git</code> 文件夹中的相关子模块文件</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rm -rf .git/modules/submodule_a</span><br></pre></td></tr></table></figure>

<h2 id="7-查看子模块"><a href="#7-查看子模块" class="headerlink" title="7. 查看子模块"></a><font size=3>7. 查看子模块</font></h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git submodule</span><br></pre></td></tr></table></figure>

<h1 id="三、远程仓库"><a href="#三、远程仓库" class="headerlink" title="三、远程仓库"></a><font size=3>三、远程仓库</font></h1><p>这一次就以我的博客站点为例了。两个仓库（后来都转成私有仓库了）的链接如下：</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://github.com/sumumm/site">sumumm&#x2F;site: 苏木的主页</a></li>
<li><a target="_blank" rel="noopener" href="https://github.com/sumumm/site-docs">sumumm&#x2F;site-docs: 苏木的site的笔记</a></li>
</ul>
<blockquote>
<p>这部分我就是在windows下进行的了。</p>
</blockquote>
<h2 id="1-添加子模块"><a href="#1-添加子模块" class="headerlink" title="1. 添加子模块"></a><font size=3>1. 添加子模块</font></h2><p>添加远程模块的时候格式是这样的：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git submodule add &lt;url&gt; &lt;repo_name&gt;</span><br></pre></td></tr></table></figure>

<p>在这里就是：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd hexo-site</span><br><span class="line">git submodule add git@github.com:sumumm/site-docs.git source/_posts/docs</span><br></pre></td></tr></table></figure>

<p>然后就会看到如下提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ≡]&gt; git submodule add git@github.com:sumumm/site-docs.git source/_posts/docs</span><br><span class="line">Cloning into &#x27;D:/sumu_blog/site/source/_posts/docs&#x27;...</span><br><span class="line">remote: Enumerating objects: 4, done.</span><br><span class="line">remote: Counting objects: 100% (4/4), done.</span><br><span class="line">remote: Compressing objects: 100% (2/2), done.</span><br><span class="line">remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0 (from 0)</span><br><span class="line">Receiving objects: 100% (4/4), done.</span><br></pre></td></tr></table></figure>

<p>就会发现在 <code>hexo-site/source/_posts/docs</code>出现了我们的测试笔记：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ≡ +2 ~0 -0 ~]&gt; ls .\source\_posts\docs\01-linux开发\</span><br><span class="line">    目录: D:\sumu_blog\site\source\_posts\docs\01-linux开发</span><br><span class="line">Mode                 LastWriteTime         Length Name</span><br><span class="line">----                 -------------         ------ ----</span><br><span class="line">-a----          2025/6/2     13:57            234 linux开发-README.md</span><br></pre></td></tr></table></figure>

<p>这个时候我们就是可以正常执行下面的命令来生成静态网页：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">hexo g</span><br><span class="line">hexo s</span><br></pre></td></tr></table></figure>

<h2 id="2-更新子模块"><a href="#2-更新子模块" class="headerlink" title="2. 更新子模块"></a><font size=3>2. 更新子模块</font></h2><h3 id="2-1-怎么更新远程最新版本？"><a href="#2-1-怎么更新远程最新版本？" class="headerlink" title="2.1 怎么更新远程最新版本？"></a><font size=3>2.1 怎么更新远程最新版本？</font></h3><p>这时候就不能单纯的用<code>git submodule update</code>，更新远程项目的最新版本是以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git submodule update --remote</span><br></pre></td></tr></table></figure>

<p>然后会有如下输出：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ≡ +2 ~0 -0 ~]&gt; git submodule update --remote</span><br><span class="line">remote: Enumerating objects: 8, done.</span><br><span class="line">remote: Counting objects: 100% (8/8), done.</span><br><span class="line">remote: Compressing objects: 100% (5/5), done.</span><br><span class="line">remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0 (from 0)</span><br><span class="line">Unpacking objects: 100% (6/6), 777 bytes | 48.00 KiB/s, done.</span><br><span class="line">From github.com:sumumm/site-docs</span><br><span class="line">   e20f97c..6d34f62  master     -&gt; origin/master</span><br><span class="line">Submodule path &#x27;source/_posts/docs&#x27;: checked out &#x27;6d34f6280a17c4dbe3049426dd2986baa680ce79&#x27;</span><br></pre></td></tr></table></figure>

<p>这个会强制更新到和子模块远程完全相同的版本。</p>
<h3 id="2-2-不加–remote为什么不行？"><a href="#2-2-不加–remote为什么不行？" class="headerlink" title="2.2 不加–remote为什么不行？"></a><font size=3>2.2 不加–remote为什么不行？</font></h3><h4 id="2-2-1-无-remote-参数"><a href="#2-2-1-无-remote-参数" class="headerlink" title="2.2.1 无 --remote 参数"></a><font size=3>2.2.1 无 <code>--remote</code> 参数</font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git submodule update</span><br></pre></td></tr></table></figure>

<ul>
<li><p><strong>数据来源</strong>：父仓库中记录的 <strong>本地提交哈希值</strong></p>
</li>
<li><p><strong>更新逻辑</strong>：</p>
</li>
</ul>
<p>（1）读取父仓库的 <code>.gitmodules</code> 配置和当前提交记录的 <strong>子模块哈希值</strong></p>
<p>（2）将子模块检出（checkout）到该哈希值对应的提交</p>
<p>（3）<strong>不连接远程仓库</strong>，仅使用本地已有的子模块仓库数据</p>
<ul>
<li><strong>适用场景</strong>：切换分支&#x2F;回退版本后，将子模块同步到父仓库记录的版本</li>
</ul>
<h4 id="2-2-2-使用-remote-参数"><a href="#2-2-2-使用-remote-参数" class="headerlink" title="2.2.2 使用 --remote 参数"></a><font size=3>2.2.2 使用 <code>--remote</code> 参数</font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git submodule update --remote</span><br></pre></td></tr></table></figure>

<ul>
<li><strong>数据来源</strong>：子模块配置的 <strong>远程仓库（origin）</strong></li>
<li><strong>更新逻辑</strong>：</li>
</ul>
<p>（1）进入子模块目录</p>
<p>（2）执行 <code>git fetch origin</code> 获取远程最新数据</p>
<p>（3）检出 <code>.gitmodules</code> 中配置分支的最新提交（如未配置则用默认分支）</p>
<p>（4）将新提交哈希记录到父仓库</p>
<h3 id="2-3-怎么确定子模块版本？"><a href="#2-3-怎么确定子模块版本？" class="headerlink" title="2.3 怎么确定子模块版本？"></a><font size=3>2.3 怎么确定子模块版本？</font></h3><p><code>git submodule update</code> 命令是怎么确认子模块的版本的？父仓库的 <strong>当前提交</strong> 中存储了子模块的 <strong>精确 Git 提交哈希值</strong>（例如 <code>160000</code> 模式的树对象）。我们可以通过以下命令查看：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git ls-tree HEAD &lt;submodule-path&gt;</span><br></pre></td></tr></table></figure>

<p>会看到如下打印信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ≡]&gt; git ls-tree HEAD .\source\_posts\docs\</span><br><span class="line">160000 commit ad2854a5528f6ce5841fe8972839b1f289f1d621  source/_posts/docs</span><br></pre></td></tr></table></figure>

<p>当执行 <code>git submodule update</code> 时，读取父仓库当前提交中子模块路径对应的 <strong>提交哈希值</strong>，进入子模块目录，执行 <code>git checkout &lt;commit-hash&gt;</code>，将子模块切换到该哈希值对应的版本（分离头指针状态）。若子模块未初始化&#x2F;克隆，先自动执行 <code>git submodule init</code> 克隆仓库。</p>
<p>所以其实子模块<strong>不会自动更新</strong>到最新提交，而是严格使用父仓库记录的旧版本。这样应该是为了在父仓库提交后，让其他协作者运行 <code>git submodule update</code> 会获得<strong>完全相同的子模块版本</strong>，确保一致性。更新的时候检出父仓库记录的提交（不联网更新）。当我们执行了<code>git submodule update --remote</code>，就会强制联网拉取子模块远程仓库的 <strong>最新提交</strong>（可以在 <code>.gitmodules</code> 中配置 <code>branch</code> 属性）。</p>
<p>但是，这个时候父仓库的记录信息并不会更新，例如，我这里有一个带子模块的仓库信息如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ≡]&gt; git ls-tree HEAD .\source\_posts\docs\</span><br><span class="line">160000 commit ad2854a5528f6ce5841fe8972839b1f289f1d621  source/_posts/docs</span><br><span class="line"></span><br><span class="line">D:\sumu_blog\site [master ≡]&gt; git submodule</span><br><span class="line"> ad2854a5528f6ce5841fe8972839b1f289f1d621 source/_posts/docs (remotes/origin/HEAD)</span><br></pre></td></tr></table></figure>

<p>可以看到，子模块的版本是ad2854a5528f6ce5841fe8972839b1f289f1d621，我们现在更新以下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ≡]&gt; git submodule update --remote</span><br><span class="line">remote: Enumerating objects: 9, done.</span><br><span class="line">remote: Counting objects: 100% (9/9), done.</span><br><span class="line">remote: Compressing objects: 100% (3/3), done.</span><br><span class="line">remote: Total 5 (delta 1), reused 5 (delta 1), pack-reused 0 (from 0)</span><br><span class="line">Unpacking objects: 100% (5/5), 636 bytes | 35.00 KiB/s, done.</span><br><span class="line">From github.com:sumumm/site-docs</span><br><span class="line">   ad2854a..8ebaaf3  master     -&gt; origin/master</span><br><span class="line">Submodule path &#x27;source/_posts/docs&#x27;: checked out &#x27;8ebaaf3f6dfcd4938b6d835b95a42f8e88d4d183&#x27;</span><br></pre></td></tr></table></figure>

<p>然后再来看一下父仓库的记录信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ≡ +0 ~1 -0 !]&gt; git ls-tree HEAD .\source\_posts\docs\</span><br><span class="line">160000 commit ad2854a5528f6ce5841fe8972839b1f289f1d621  source/_posts/docs</span><br><span class="line"></span><br><span class="line">D:\sumu_blog\site [master ≡ +0 ~1 -0 !]&gt; git submodule</span><br><span class="line">+8ebaaf3f6dfcd4938b6d835b95a42f8e88d4d183 source/_posts/docs (remotes/origin/HEAD)</span><br></pre></td></tr></table></figure>

<p>可以发现当前子模块的版本是8ebaaf3f6dfcd4938b6d835b95a42f8e88d4d183，但是父仓库还是原来的提交记录，当我们执行 <code>git submodule update</code> 时，子模块的版本就会回到之前的。例如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ≡ +0 ~1 -0 !]&gt; git submodule update</span><br><span class="line">Submodule path &#x27;source/_posts/docs&#x27;: checked out &#x27;ad2854a5528f6ce5841fe8972839b1f289f1d621&#x27;</span><br><span class="line">   </span><br><span class="line">D:\sumu_blog\site [master ≡]&gt; git ls-tree HEAD .\source\_posts\docs\</span><br><span class="line">160000 commit ad2854a5528f6ce5841fe8972839b1f289f1d621  source/_posts/docs</span><br><span class="line"></span><br><span class="line">D:\sumu_blog\site [master ≡]&gt; git submodule       </span><br><span class="line"> ad2854a5528f6ce5841fe8972839b1f289f1d621 source/_posts/docs (heads/master-6-gad2854a)</span><br></pre></td></tr></table></figure>



<h3 id="2-4-同步配置变更"><a href="#2-4-同步配置变更" class="headerlink" title="2.4 同步配置变更"></a><font size=3>2.4 同步配置变更</font></h3><h4 id="2-4-1-提交子模块的改动"><a href="#2-4-1-提交子模块的改动" class="headerlink" title="2.4.1 提交子模块的改动"></a><font size=3>2.4.1 提交子模块的改动</font></h4><p>那么我们怎么更新父仓库的记录信息？我们先回到父仓库看一下状态：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [<span class="type">master</span> ≡ +<span class="number">0</span> ~<span class="number">1</span> -<span class="number">0</span> !]&gt; git status</span><br><span class="line">On branch master</span><br><span class="line">Your branch is up to date with <span class="string">&#x27;origin/master&#x27;</span>.</span><br><span class="line"></span><br><span class="line">Changes not staged <span class="keyword">for</span> commit:</span><br><span class="line">  (use <span class="string">&quot;git add &lt;file&gt;...&quot;</span> to update what will be committed)</span><br><span class="line">  (use <span class="string">&quot;git restore &lt;file&gt;...&quot;</span> to discard changes <span class="keyword">in</span> working directory)</span><br><span class="line">        modified:   source/_posts/docs (new commits)</span><br><span class="line"></span><br><span class="line">no changes added to commit (use <span class="string">&quot;git add&quot;</span> and/or <span class="string">&quot;git commit -a&quot;</span>)</span><br></pre></td></tr></table></figure>

<p>可以看到子模块有了新的提交，这个时候我们可以执行：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#git add path/to/submodule</span></span><br><span class="line">git add source/_posts/docs</span><br><span class="line">git commit <span class="literal">-m</span> <span class="string">&quot;更新子模块版本&quot;</span></span><br></pre></td></tr></table></figure>

<p>然后父仓库记录的版本就会更新了：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [<span class="type">master</span> ≡ +<span class="number">0</span> ~<span class="number">1</span> -<span class="number">0</span> ~]&gt; git commit <span class="literal">-m</span> <span class="string">&quot;更新子模块版本&quot;</span></span><br><span class="line">[<span class="type">master</span> <span class="number">4699</span><span class="type">ae0</span>] 更新子模块版本</span><br><span class="line"> <span class="number">1</span> file changed, <span class="number">1</span> insertion(+), <span class="number">1</span> deletion(-)</span><br><span class="line"></span><br><span class="line">D:\sumu_blog\site [<span class="type">master</span> ↑<span class="number">1</span>]&gt; git <span class="built_in">ls</span><span class="literal">-tree</span> HEAD .\source\_posts\docs\</span><br><span class="line"><span class="number">160000</span> commit <span class="number">8</span>ebaaf3f6dfcd4938b6d835b95a42f8e88d4d183  source/_posts/docs</span><br></pre></td></tr></table></figure>

<h4 id="2-4-2-新-URL-配置"><a href="#2-4-2-新-URL-配置" class="headerlink" title="2.4.2 新 URL 配置"></a><font size=3>2.4.2 新 URL 配置</font></h4><p>或者也可以用下面这个命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git submodule sync</span><br><span class="line">git submodule sync --recursive # --recursive 参数处理嵌套子模块</span><br></pre></td></tr></table></figure>

<ul>
<li><p><strong>更新父仓库的本地配置</strong>：将父仓库中 <code>.git/config</code> 文件里的子模块 URL 更新为 <code>.gitmodules</code> 文件中的最新 URL。</p>
</li>
<li><p><strong>更新子模块的本地配置</strong>：递归更新子模块自身目录内的 <code>.git/config</code> 中的远程仓库 URL（通常是 <code>origin</code>）。</p>
</li>
</ul>
<p>例如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">D:\sumu_blog\site [master ↑1]&gt; git submodule     </span><br><span class="line"> e20f97cf1881ac8df94479241051930426563c9b source/_posts/docs (heads/master)</span><br><span class="line"> </span><br><span class="line">D:\sumu_blog\site [master ↑1]&gt; git submodule update --remote</span><br><span class="line">Submodule path &#x27;source/_posts/docs&#x27;: checked out &#x27;ee6209b3d6071b5fd06905c2a79c012fe1d1f099&#x27;</span><br><span class="line"></span><br><span class="line">D:\sumu_blog\site [master ↑1 +0 ~1 -0 !]&gt; git submodule sync</span><br><span class="line">Synchronizing submodule url for &#x27;source/_posts/docs&#x27;</span><br><span class="line"></span><br><span class="line">D:\sumu_blog\site [master ↑1 +0 ~1 -0 !]&gt; git submodule</span><br><span class="line">+ee6209b3d6071b5fd06905c2a79c012fe1d1f099 source/_posts/docs (remotes/origin/HEAD)</span><br></pre></td></tr></table></figure>

<blockquote>
<p>Tips：</p>
<p><code>git submodule sync</code> 是 <strong>子模块仓库地址变更后的关键修复命令</strong>，它可以确保：</p>
<p>（1）父仓库的本地配置（<code>.git/config</code>）与声明文件（<code>.gitmodules</code>）一致</p>
<p>（2）子模块自身的远程仓库配置同步更新</p>
<p>（3）该命令<strong>不会修改子模块的代码版本</strong>，仅更新配置。代码更新仍需通过 <code>git submodule update</code> 完成。</p>
</blockquote>
<h2 id="3-clone带子模块的仓库"><a href="#3-clone带子模块的仓库" class="headerlink" title="3. clone带子模块的仓库"></a><font size=3>3. clone带子模块的仓库</font></h2><p>clone主仓库后，子仓库是没有代码的，还要执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git submodule init   # 初始化子模块</span><br><span class="line">git submodule update # 更新子模块代码</span><br></pre></td></tr></table></figure>

<p>或者直接用下面的命令，一步到位：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone --recursive &lt;repo_url&gt;</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/16811b15.html">LV01-Git-06-子模块</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2025年06月02日 - 14:43</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/16811b15.html" title="LV01-Git-06-子模块">https://sumumm.github.io/post/16811b15.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/Git/" rel="tag"><i class="fa fa-tag"></i> Git</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/4a17b156.html" rel="prev" title="Hello World">
                  <i class="fa fa-angle-left"></i> Hello World
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/f5b59420.html" rel="next" title="LV10-01-LCD驱动-04-Linux下的LCD驱动">
                  LV10-01-LCD驱动-04-Linux下的LCD驱动 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
